package com.milk.task;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.milk.entity.UserSignIn;
import com.milk.mapper.UserSignInMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class SignInTask {

    @Autowired
    private UserSignInMapper userSignInMapper;

    /**
     * 每天凌晨1点处理已完成的订单
     */
    @Scheduled(cron = "59 59 23 * * ? ")
    public void isSignIn(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime old = now.plusDays(-1);

        QueryWrapper<UserSignIn> qw = new QueryWrapper<>();
        //查找出今天没有签到的用户
        qw.lt("updatetime",old);

        UserSignIn userSignIn = new UserSignIn();
        userSignIn.setConsecutiveDays(0);
        userSignInMapper.update(userSignIn,qw);
    }

}
